<template>
  <div class="app-container">

    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="编号" prop="code">
        <el-input v-model="queryParams.code" placeholder="请输入编号" clearable size="small" />
      </el-form-item>
      <el-form-item label="用户昵称">
        <el-input v-model="queryParams.accountId" placeholder="请输入用户" clearable size="small" />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择" clearable size="small">
          <el-option label="全部" value="" />
          <el-option label="待审核" :value="1" />
          <el-option label="通过" :value="2" />
          <el-option label="拒绝" :value="3" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="userChatroomApplyList">
      <el-table-column label="用户昵称" align="center" prop="accountId" />
      <el-table-column label="品类" align="center" prop="chatroomTypeId" />
      <el-table-column label="真人照" align="center" prop="photo" />
      <el-table-column label="申请理由" align="center" prop="reason" :show-overflow-tooltip="true"/>
      <el-table-column label="编号" align="center" prop="code" />
      <el-table-column label="申请次数" align="center" prop="counts" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.applyTime===1">待审核</span>
          <span v-else-if="scope.row.applyTime===2">已通过</span>
          <span v-else-if="scope.row.applyTime===3">已拒绝</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="提交时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime?parseTime(scope.row.createTime):'--' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核时间" align="center" prop="applyTime" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.applyTime?parseTime(scope.row.applyTime):'--' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核人" align="center" prop="applyBy" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:userChatroomApply:edit']"
          >审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog title="聊天室审核" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="申请用户" >
          {{form.userNike}}
        </el-form-item>
        <el-form-item label="聊天室审核" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio :label="2">审核通过</el-radio>
            <el-radio :label="3">审核不通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="原因" prop="appylyText">
          <el-input type="textarea" v-model="form.appylyText" :rows="3"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listUserChatroomApply, getUserChatroomApply, updateUserChatroomApply } from "@/api/system/userChatroomApply";

export default {
  name: "UserChatroomApply",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 聊天室申请表格数据
      userChatroomApplyList: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: undefined,
        accountId: undefined,
        chatroomTypeId: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        status: [
          { required: true, message: "请选择审核状态", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询聊天室申请列表 */
    getList() {
      this.loading = true;
      listUserChatroomApply(this.queryParams).then(response => {
        this.userChatroomApplyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getUserChatroomApply(id).then(response => {
        this.form = response.data;
        this.open = true;
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateUserChatroomApply(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }
          });
        }
      });
    },
  }
};
</script>